#include <iostream>
#include <fstream>

bool OokToBrainfuck (char* InFileName, char* OutFileName)
{
	char Lign[12];

	std::ifstream InFile;
	std::ofstream OutFile;

	InFile.open(InFileName);
	OutFile.open(OutFileName);

	if(!InFile.is_open())
	{
		std::cout << "Impossible d'ouvrir le fichier d'entrée" << std::endl;
	}
	else
	{
		while (InFile.get(Lign, 11))
		{
			if (Lign[3] == '.' && Lign[8] =='?')
				OutFile << '>';

			else if (Lign[3] == '?' && Lign[8] == '.')
				OutFile << '<';

			else if (Lign[3] == '.' && Lign[8] == '.')
				OutFile << '+';

			else if (Lign[3] == '!' && Lign[8] == '!')
				OutFile << '-';

			else if (Lign[3] == '!' && Lign[8] == '.')
				OutFile << '.';

			else if (Lign[3] == '.' && Lign[8] == '!')
				OutFile << ',';

			else if (Lign[3] == '!' && Lign[8] == '?')
				OutFile << '[';

			else if (Lign[3] == '?' && Lign[8] == '!')
				OutFile << ']';

			else
			{
				InFile.close();
				OutFile.close();
				return 0;
			}

			Lign[3] = '0';
			Lign[8] = '0';
		}
	}

	InFile.close();
	OutFile.close();
	return 1;
}



bool BrainfuckToOok (char* InFileName, char* OutFileName)
{
	char Lign;

	std::ifstream InFile;
	std::ofstream OutFile;

	InFile.open(InFileName);
	OutFile.open(OutFileName);

	if(!InFile.is_open())
	{
		std::cout << "Impossible d'ouvrir le fichier d'entrée" << std::endl;
	}
	else
	{
		while (InFile.get(Lign))
		{
			switch (Lign)
			{
				case '>' : 	OutFile << "Ook. Ook? "; break;
				case '<' : 	OutFile << "Ook? Ook. "; break;
				case '+' : 	OutFile << "Ook. Ook. "; break;
				case '-' : 	OutFile << "Ook! Ook! "; break;
				case '.' : 	OutFile << "Ook! Ook. "; break;
				case ',' : 	OutFile << "Ook. Ook! "; break;
				case '[' : 	OutFile << "Ook! Ook? "; break;
				case ']' : 	OutFile << "Ook? Ook! "; break;
				case '\n':  OutFile << std::endl; break;
				default :
							InFile.close();
							OutFile.close();
							return 0;
			}
		}

		InFile.close();
		OutFile.close();
		return 1;
	}

	InFile.close();
	OutFile.close();
	return 1;
}


int main ()
{
	char* OokFile ("/home/titi/File_Ook");
	char* BrainfuckFile ("/home/titi/File_Brainfuck");

	if ( OokToBrainfuck(OokFile, BrainfuckFile) == 1 )
		std::cout << "ok" << std::endl;
	else
		std::cout << "error" << std::endl;

	if ( BrainfuckToOok(BrainfuckFile, OokFile) == 1 )
			std::cout << "ok" << std::endl;
		else
			std::cout << "error" << std::endl;
}

